#include <wx/wxprec.h>

#ifdef __BORLANDC__
    #pragma hdrstop
#endif

#ifndef WX_PRECOMP
    #include <wx/wx.h>
#endif

#include "wxstatectrl.h"

IMPLEMENT_DYNAMIC_CLASS( wxState, wxObject )

wxStateCtrl::wxStateCtrl( wxWindow* parent, wxWindowID id, wxPoint pos, wxSize size, int style )
: wxControl( parent, id, pos, size, style )
{
}

bool wxStateCtrl::AddState( wxState* state )
{
	wxASSERT_MSG( state, wxT("State is null.") );
	std::pair< wxStateMapIterator, bool > work = m_states.insert( wxStateMap::value_type( state->m_id, state ) );
	return work.second;
}

bool wxStateCtrl::RemoveState( wxStateId id )
{
	return ( 0 != m_states.erase( id ) );
}

wxState* wxStateCtrl::GetState( wxStateId id )
{
	wxStateMapIterator state = m_states.find( id );
	if ( m_states.end() == state )
	{
		return NULL;
	}
	else
	{
		return state->second;
	}
}

size_t wxStateCtrl::GetStateCount()
{
	return m_states.size();
}

bool wxStateCtrl::Exists( wxStateId id )
{
	return ( 0 != m_states.count( id ) );
}

wxStateCtrl::~wxStateCtrl()
{
	wxStateMapIterator state;
	for ( state = m_states.begin(); state != m_states.end(); ++state )
	{
		delete state->second;
	}
}
